package _1_PIO.excel.样式;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 设置字体
 */
public class _5_Fonts {

    @Test
    public void _2003(){

    }

    @Test
    public void _2007() throws IOException {

        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();
        Row row = sheet.createRow(1);

        Font font = workbook.createFont();
        font.setFontHeightInPoints((short)24);
        font.setFontName("Courier New");
        font.setItalic(true);
        font.setStrikeout(true);
        font.setBold(true);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFont(font);

        Cell cell = row.createCell(1);
        cell.setCellValue("This is a test of fonts");
        cell.setCellStyle(cellStyle);

        try(OutputStream outputStream = new FileOutputStream("D://workbook.xlsx")){
            workbook.write(outputStream);
        }
        finally{
            workbook.close();
        }
    }
}
